<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link href="style/demo.css" rel="stylesheet" type="text/css"/>
    <script src="scripts/jquery-1.9.1.js" type="text/javascript"></script>
    <script src="scripts/demo.js" type="text/javascript"></script>
    <script type="text/javascript"
            src="http://api.map.baidu.com/api?v=2.0&ak=QDvLUEl5NjFnbTDP9fu19VwghS9mNTPS"></script>
    <script type="text/javascript"
            src="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <link rel="stylesheet" href="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.css"/>
</head>
<body>
<div class="demo_main">
    <fieldset class="demo_content">
        <div style="min-height: 500px; width: 100%;" id="map">
        </div>
        <script type="text/javascript">
            var markerArr;
            axios.get("/address/findAllByMap").then(response => {
                console.log(response.data.data);
                if (response.data.flag) {
                    markerArr = response.data.data;
                    map_load();
                } else {
                    this.$message.error(response.data.message);
                }
            });

            function map_init() {
                var map = new BMap.Map("map"); // 创建Map实例
                //var point = new BMap.Point(120.188876, 30.228258); //地图中心点
                map.centerAndZoom("杭州", 10); // 初始化地图,设置中心点坐标和地图级别。
                map.enableScrollWheelZoom(true); //启用滚轮放大缩小
                //地图、卫星、混合模式切换
                map.addControl(new BMap.MapTypeControl({mapTypes: [BMAP_NORMAL_MAP, BMAP_SATELLITE_MAP, BMAP_HYBRID_MAP]}));
                //向地图中添加缩放控件
                var ctrlNav = new window.BMap.NavigationControl({
                    anchor: BMAP_ANCHOR_TOP_LEFT,
                    type: BMAP_NAVIGATION_CONTROL_LARGE
                });
                map.addControl(ctrlNav);
                //向地图中添加缩略图控件
                var ctrlOve = new window.BMap.OverviewMapControl({
                    anchor: BMAP_ANCHOR_BOTTOM_RIGHT,
                    isOpen: 1
                });
                map.addControl(ctrlOve);
                //向地图中添加比例尺控件
                var ctrlSca = new window.BMap.ScaleControl({
                    anchor: BMAP_ANCHOR_BOTTOM_LEFT
                });
                map.addControl(ctrlSca);

                var point = new Array(); //存放标注点经纬信息的数组
                var marker = new Array(); //存放标注点对象的数组
                var info = new Array(); //存放提示信息窗口对象的数组
                var searchInfoWindow = new Array();//存放检索信息窗口对象的数组
                for (var i = 0; i < markerArr.length; i++) {
                    var p0 = markerArr[i].lng; //
                    var p1 = markerArr[i].lat; //按照原数组的point格式将地图点坐标的经纬度分别提出来
                    point[i] = new window.BMap.Point(p0, p1); //循环生成新的地图点
                    marker[i] = new window.BMap.Marker(point[i]); //按照地图点坐标生成标记
                    map.addOverlay(marker[i]);
                    // marker[i].setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
                    //显示marker的title，marker多的话可以注释掉
                    var label = new window.BMap.Label(markerArr[i].organizationName, {offset: new window.BMap.Size(20, -10)});
                    marker[i].setLabel(label);
                    // 创建信息窗口对象
                    info[i] = "<p style='font-size:12px;lineheight:1.8em'>" + "</br>地址：" + markerArr[i].addressDetail + "</br> 电话：" + markerArr[i].telephone + "</br></p>";
                    //创建百度样式检索信息窗口对象
                    searchInfoWindow[i] = new BMapLib.SearchInfoWindow(map, info[i], {
                        title: markerArr[i].title,      //标题
                        width: 290,             //宽度
                        height: 55,              //高度
                        panel: "panel",         //检索结果面板
                        enableAutoPan: true,     //自动平移
                        searchTypes: [
                            BMAPLIB_TAB_SEARCH,   //周边检索
                            BMAPLIB_TAB_TO_HERE,  //到这里去
                            BMAPLIB_TAB_FROM_HERE //从这里出发
                        ]
                    });
                    //添加点击事件
                    marker[i].addEventListener("click",
                        (function (k) {
                            // js 闭包
                            return function () {
                                //将被点击marker置为中心
                                //map.centerAndZoom(point[k], 18);
                                //在marker上打开检索信息窗口
                                searchInfoWindow[k].open(marker[k]);
                            }
                        })(i)
                    );
                }
            }

            //异步调用百度js
            function map_load() {
                var load = document.createElement("script");
                load.src = "http://api.map.baidu.com/api?v=2.0&callback=map_init";
                document.body.appendChild(load);
            }
        </script>
    </fieldset>
</div>
</body>
</html>


<!--
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <style type="text/css">
        body, html, #allmap {
            width: 100%;
            height: 100%;
            overflow: hidden;
            margin: 0;
            font-family: "微软雅黑";
        }
    </style>
    <script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=QDvLUEl5NjFnbTDP9fu19VwghS9mNTPS"></script>
    <title>地图展示</title>
</head>
<body>
<div id="l-map"></div>
<div id="r-result">
    <input type="button" value="批量反地址解析+商圈" onclick="bdGEO(0)" />
    <div id="result"></div>
</div>
</body>
</html>
<script type="text/javascript">
    /*// 百度地图API功能
    const map = new BMap.Map("allmap");    // 创建Map实例
    map.centerAndZoom(new BMap.Point(120.30, 30.33), 11);  // 初始化地图,设置中心点坐标和地图级别
    //添加地图类型控件
    map.addControl(new BMap.MapTypeControl({
        mapTypes: [
            BMAP_NORMAL_MAP,
            BMAP_HYBRID_MAP
        ]
    }));
    map.setCurrentCity("杭州");          // 设置地图显示的城市 此项是必须设置的
    map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放*/

    // 百度地图API功能
    var map = new BMap.Map("l-map");
    map.centerAndZoom(new BMap.Point(116.328749,40.026922), 13);
    map.enableScrollWheelZoom(true);
    var index = 0;
    var myGeo = new BMap.Geocoder();
    var adds = [
        new BMap.Point(116.307852,40.057031),
        new BMap.Point(116.313082,40.047674),
        new BMap.Point(116.328749,40.026922),
        new BMap.Point(116.347571,39.988698),
        new BMap.Point(116.316163,39.997753),
        new BMap.Point(116.345867,39.998333),
        new BMap.Point(116.403472,39.999411),
        new BMap.Point(116.307901,40.05901)
    ];
    for(var i = 0; i<adds.length; i++){
        var marker = new BMap.Marker(adds[i]);
        map.addOverlay(marker);
        marker.setLabel(new BMap.Label("我是商圈:"+(i+1),{offset:new BMap.Size(20,-10)}));
    }
    function bdGEO(){
        var pt = adds[index];
        geocodeSearch(pt);
        index++;
    }
    function geocodeSearch(pt){
        if(index < adds.length-1){
            setTimeout(window.bdGEO,400);
        }
        myGeo.getLocation(pt, function(rs){
            var addComp = rs.addressComponents;
            document.getElementById("result").innerHTML += index + ". " +adds[index-1].lng + "," + adds[index-1].lat + "："  + "商圈(" + rs.business + ")  结构化数据(" + addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber + ")<br/><br/>";
        });
    }


</script>-->
